﻿using MediatR;
using RBAC.MaHaiBo.API.Application.Command.TracingCommand;
using RBAC.MaHaiBo.Entity.Traceability;
using RBAC.MaHaiBo.Service.TraceabilityService;

namespace RBAC.MaHaiBo.API.Application.CommandHandlers.TracingHandler
{
    public class TracingCreateCommandHandler:IRequestHandler<TracingCreateCommand, int>
    {
        /// <summary>
        /// 溯源服务层
        /// </summary>
        ITracingService TSer;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="TSer">溯源服务层</param>
        public TracingCreateCommandHandler(ITracingService TSer)
        {
            this.TSer = TSer;
        }

        public async Task<int> Handle(TracingCreateCommand request, CancellationToken cancellationToken)
        {
            return await TSer.AddTracing(new Tracing() { TracingId= request.TracingId, CommodityId = request.CommodityId, LOT = request.LOT, ProductionPermit = request.ProductionPermit, ShelfLife = request.ShelfLife, Manufacturer = request.Manufacturer, SurfacePlot = request.SurfacePlot, AddName = request.AddName, AddTime = request.AddTime });
        }
    }
}
